package com.zuxia.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zuxia.dto.balance.BalanceDto;
import com.zuxia.dto.commission.CommissionDto;
import com.zuxia.entity.Balance;
import com.zuxia.mapper.BalanceMapper;
import com.zuxia.param.BalanceParam;
import com.zuxia.service.BalanceService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author laoli
 * @since 2024-11-19
 */
@Service
public class BalanceServiceImp extends ServiceImpl<BalanceMapper, Balance> implements BalanceService {
    @Resource
    private BalanceMapper balanceMapper;
    @Override
    public List<Balance> getBalance(BalanceParam param) {
        LambdaQueryWrapper<Balance> wrapper = new LambdaQueryWrapper<>();
        //判断是否给收支状态
        if(!param.getBalanceStatus().isEmpty()){
            wrapper.eq(Balance::getBalanceStatus,Integer.valueOf(param.getBalanceStatus()));
        }
        List<Balance> balances = balanceMapper.selectList(wrapper);
        return balances;
    }

    @Override
    public BalanceDto yue() {
        List<Balance> balances = balanceMapper.selectList(null);
        BigDecimal zC = BigDecimal.ZERO;
        BigDecimal sR = BigDecimal.ZERO;
        BalanceDto result = new BalanceDto();
        for (Balance balance : balances) {
            //支出
            if(balance.getBalanceStatus()==1){
                BigDecimal zcMoney=balance.getBalanceMoney();
                zC= zC.add(zcMoney);
            }
            //收入
            else{
                BigDecimal srMoney=balance.getBalanceMoney();
                sR=sR.add(srMoney);
            }
            result.setZhiChu(zC);
            result.setShouRu(sR);
        }
        return result;
    }
}
